/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.invoice.controller.reports;

/**
 *
 * @author laura
 */
 
import com.invoice.busines.dto.ComprobanteDTO;
import java.util.HashMap;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
 
@ManagedBean(name = "comprobanteReportsBean")
@SessionScoped
public class ComprobanteReportsBean extends AbstractReportBean {
    ComprobanteDTO comprobanteDTO = new ComprobanteDTO();
    private final String COMPILE_FILE_NAME = "newReport";

    public void setComprobanteDTO(ComprobanteDTO comprobanteDTO) {
        this.comprobanteDTO = comprobanteDTO;
    }

    public ComprobanteDTO getComprobanteDTO() {
        return comprobanteDTO;
    }
 
    @Override
    protected String getCompileFileName() {
        return COMPILE_FILE_NAME;
    }
 
    @Override
    protected Map<String, Object> getReportParameters() {
        Map<String, Object> parameters = new HashMap<String, Object>(); 
        if(comprobanteDTO.getTipoComprobante()!=null){
            parameters.put("tipo_comprobante", ReportConfigUtil.checkNull(comprobanteDTO.getTipoComprobante().toString()));
        } else {
            parameters.put("tipo_comprobante", "");
        }
        parameters.put("numero_comprobante", ReportConfigUtil.checkNull(comprobanteDTO.getNumComp()));
        parameters.put("fecha", ReportConfigUtil.checkNull(comprobanteDTO.getFecha()));
        if(comprobanteDTO.getClienteDTO() != null){
            parameters.put("nombre_cliente", ReportConfigUtil.checkNull(comprobanteDTO.getClienteDTO().getNombre()));
            parameters.put("direccion_cliente", ReportConfigUtil.checkNull(comprobanteDTO.getClienteDTO().getDireccion()));
        } else{
            parameters.put("nombre_cliente", "");
            parameters.put("direccion_cliente", "");
        }
        parameters.put("total", ReportConfigUtil.checkNull(comprobanteDTO.getTotal())); 
        return parameters;
    }
    @Override
    protected JRBeanCollectionDataSource getDataSource(){
        JRBeanCollectionDataSource beanColDataSource = null;
        if(comprobanteDTO.getComprobantedetalles() != null){
            beanColDataSource = new JRBeanCollectionDataSource(comprobanteDTO.getComprobantedetalles());
        }
        return beanColDataSource;
    }
    public void execute() {
        String result = "";
        try {
            super.prepareReport();
        } catch (Exception e) {
            // make your own exception handling
            e.printStackTrace();
        }
 
//        return result;
    }
}
